# movies/models.py

from django.db import models
import os

def poster_path(instance, filename):
    return os.path.join('posters', f'{instance.title}.jpg')

class Movie(models.Model):
    title = models.CharField(max_length=200, verbose_name="电影名称")
    rating = models.FloatField(verbose_name="评分")
    director = models.CharField(max_length=200, verbose_name="导演")
    actors = models.CharField(max_length=200, verbose_name="演员")
    year = models.CharField(max_length=50, verbose_name="年份")
    country = models.CharField(max_length=100, verbose_name="产地")
    genre = models.CharField(max_length=100, verbose_name="类型")
    quote = models.CharField(max_length=300, blank=True, verbose_name="金句")
    poster = models.ImageField(upload_to=poster_path, verbose_name="海报")
    #douban_url = models.URLField(verbose_name="豆瓣链接")
    
    class Meta:
        ordering = ['rating']
        verbose_name = "电影"
        verbose_name_plural = "电影"
    
    def __str__(self):
        return f"{self.rating}. {self.title} ({self.year})"
